Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'instanceandevents' endpoint when updating process state #937

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

martinothamar
Copy link
Contributor

@martinothamar martinothamar commented Nov 28, 2024

Description

Uses the new endpoint which commits new process state and instance events in one transaction.

The related tests were a little funny. Test names said they were testing more than they actually were, it seems like most of the variation comes from the AltinnTaskType thingy.

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

}
else
{
_logger.LogError($"Unable to update instance process with instance id {instance.Id}");

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

Copilot Autofix AI 4 days ago

To fix the problem, we need to sanitize the instance.Id before logging it. This can be done by removing any newline characters from the instance.Id to prevent log forging. We will use the String.Replace method to achieve this.

  1. Identify the logging statement that uses instance.Id.
  2. Sanitize the instance.Id by removing newline characters before logging it.
  3. Ensure that the fix does not change the existing functionality of the code.
Suggested changeset 1
src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs b/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs
--- a/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs
+++ b/src/Altinn.App.Core/Infrastructure/Clients/Storage/InstanceClient.cs
@@ -189,3 +189,4 @@
         {
-            _logger.LogError($"Unable to update instance process with instance id {instance.Id}");
+            string sanitizedInstanceId = instance.Id.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
+            _logger.LogError($"Unable to update instance process with instance id {sanitizedInstanceId}");
             throw await PlatformHttpException.CreateAsync(response);
EOF
@@ -189,3 +189,4 @@
{
_logger.LogError($"Unable to update instance process with instance id {instance.Id}");
string sanitizedInstanceId = instance.Id.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
_logger.LogError($"Unable to update instance process with instance id {sanitizedInstanceId}");
throw await PlatformHttpException.CreateAsync(response);
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link

sonarcloud bot commented Nov 28, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
39.1% Coverage on New Code (required ≥ 65%)
50.0% Condition Coverage on New Code (required ≥ 65%)

See analysis details on SonarQube Cloud

@@ -683,6 +691,10 @@ [FromRoute] Guid instanceGuid
ProcessChangeResult startResult = await _processEngine.GenerateProcessStartEvents(processStartRequest);

targetInstance = await _instanceClient.CreateInstance(org, app, targetInstance);
foreach (var instanceEvent in startResult.ProcessStateChange?.Events ?? [])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These loops are needed because GenerateProcessStartEvents is creating the events, at which point InstanceId is null..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a bug before this fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, as it started to happen after switching to the new endpoint.. Don't know why, will do some digging to make sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants